<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/admin/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/admin/lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui/css/H-ui.css" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/admin/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/skin/default/skin.css" id="skin" />
    <link rel="stylesheet" type="text/css" href="/admin/static/h-ui.admin/css/style.css" />
    <!--[if IE 6]>
    <script type="text/javascript" src="/admin/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title></title>
    <style>
        label.error {
            position: absolute;
            right: 0px;
            top: 18px;
            color: #ef392b;
            font-size: 12px;
        }
        input[type=text] {
            /* width:50px; */
            text-align:center
        }
        .t-a-l{
            text-align: left!important;
            padding-left: 3px!important;
        }
        .col-1, .col-2, .col-3, .col-4, .col-5, .col-6, .col-7, .col-8, .col-9, .col-10, .col-11, .col-12, .col-xs-1, .col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 {
            padding-left: 0px;
            padding-right: 0px;
            /* border:solid 1px #ef392b ; */
        }
        @media (max-width: 767px){
            .form-horizontal .form-label {
                text-align: right;
            }
        }
        .row {
            margin-left: 0px;
            margin-right: 0px;
        }
        .form .row {
            margin-top: 7px;
        }
    </style>
</head>

<body>
    <article class="page-container">
        <div class="mb-15">
            <div class="f-l" style="width:50%">
                {{-- <b>　条形码：</b>{{ $sample_info_data->bar_code }}<br> --}}
                <b>　条形码：</b><span style="color:red;font-size:18px;">{{ $sample_info_data->bar_code }}</span><br>
                <b>样品名称：</b>{{ $gaiyao_data->tool_name }}<br>
                <b>检验标准：</b>{{ $gaiyao_data->std_num }}<br>
                <b>额定电压：</b>{{ $gaiyao_data->voltage }}<br>
                <b>　　分类：</b>{{ $gaiyao_data->class }}<br>
                <b>样品状态：</b>{{ $sample_info_data->sample_status }}<br>
            </div>
            <div class="f-l" style="width:50%">
                <b>　自编号：</b>{{ $sample_info_data->self_num }}<br>
                <b>生产厂家：</b>{{ $sample_info_data->manufacturer }}<br>
                <b>生产日期：</b>{{ $sample_info_data->production_date }}<br>
                <b>规格型号：</b>{{ $sample_info_data->guige_xinghao }}<br>
                <b>　　商标：</b>{{ $sample_info_data->brand }}<br>
                <b>检验周期：</b>{{ $cycle }}年<br>
            </div>
            <div style="clear:both"></div>
        </div>

        <div class="cl pd-5 bg-1 bk-gray mt-10 mb-10">
            {{-- <span class="l">
                <b>条形码：</b><input type="text" class="input-text" value="" placeholder="后三位" id="bar-code" style="width:60px">
            </span>
            <span class="l ml-10">
                <a class="btn btn-primary radius" href="javascript:;" onclick="goto_jump()">跳转</a> 
            </span> --}}
            <span class="r mr-10">
                @if ($sample_id_next)
                    <a class="btn btn-primary radius" href="javascript:;" onclick="goto_pre_next({{ $sample_id_next }})">下一个</a>
                @else 
                    <a class="btn radius disabled" href="javascript:;">下一个</a>
                @endif
            </span>
            <span class="r mr-20">
                @if ($sample_id_pre)
                    <a class="btn btn-primary radius" href="javascript:;" onclick="goto_pre_next({{ $sample_id_pre }})">上一个</a>
                @else 
                    <a class="btn radius disabled" href="javascript:;">上一个</a>
                @endif
            </span>
        </div>

        <ul id="Huifold" class="Huifold">
        @foreach ($items_data as $key=>$val)
            <form autocomplete="off" id="form-@php echo $key; @endphp">
                <li class="item">
                    <h4>
                        {{ $val->name }} 
                        @if ($val->res === 1)
                            <span class="badge badge-success radius">符合</span>
                        @elseif ($val->res === 0)
                            <span class="badge badge-danger radius">不符合</span>
                        @endif
                        <b>+</b>
                    </h4>
                    <div class="info">
                        <b style="color:blue">检验标准</b>&emsp;
                        @php
                            $yaoqiu = DB::table('a_std_tool_item_rel')->where([
                                ['std_id','=',$gaiyao_data->std_id],
                                ['tool_id','=',$gaiyao_data->tool_id],
                                ['testitem_id','=',$val->item_id]
                            ])->value('jishu_yaoqiu');

                            $key_condition = DB::table('a_condition_key')->select('id','key','unit')->where([
                                ['std_id','=',$gaiyao_data->std_id],
                                ['tool_id','=',$gaiyao_data->tool_id],
                                ['item_id','=',$val->item_id]
                            ])->orderBy('sort')->get();

                            foreach ($key_condition as $k => $v) {
                                $val_condition = DB::table('a_condition')->where('condition_key_id','=',$v->id)->whereIn('vol_class_id',[0,$gaiyao_data->vol_id,$gaiyao_data->class_id])->value('val');
                                echo "<b>{$v->key}：</b>$val_condition{$v->unit}&emsp;";
                            }

                            echo "<b>要求：</b>$yaoqiu";
                            echo "<hr style='margin:5px;background-color:#ddd;height:1px;width:100%;border:none;'>";
                        @endphp

                        <input type="hidden" name="item_id" value="{{ $val->id }}">{{-- 这里的item_id指的是a_item_data表的id --}}
                        <input type="hidden" name="cycle" value="{{ $cycle }}">{{-- 周期 --}}

                        <b style="color:blue">原始记录</b>&emsp;<br>
                        <div class="" style="margin-left: -15px;margin-right: -15px;">
                            <div class="f-l form form-horizontal" style="width:39%;border-right:1px dotted #ddd">
                                <div class="row cl">
                                    <label class="form-label col-xs-4"><b>天气：</b></label>
                                    <div class="formControls col-xs-5">
                                        <input type='text' class="input-text" name="wea" value='{{$val->wea}}'>
                                    </div>
                                </div>
                                <div class="row cl">
                                    <label class="form-label col-xs-4"><b>大气压力：</b></label>
                                    <div class="formControls col-xs-5">
                                        <input type='text' class="input-text" name="pressure" value='{{$val->pressure}}'>
                                    </div>
                                    <label class="form-label t-a-l col-xs-3">kPa</label>
                                </div>
                                <div class="row cl">
                                    <label class="form-label col-xs-4"><b>环境温度：</b></label>
                                    <div class="formControls col-xs-5">
                                        <input type='text' class="input-text" name="temp" value='{{$val->temp}}'>
                                    </div>
                                    <label class="form-label t-a-l col-xs-3">℃</label>
                                </div>
                                <div class="row cl">
                                    <label class="form-label col-xs-4"><b>相对湿度：</b></label>
                                    <div class="formControls col-xs-5">
                                        <input type='text' class="input-text" name="hum" value='{{$val->hum}}'>
                                    </div>
                                    <label class="form-label t-a-l col-xs-3">%</label>
                                </div>
                            </div>

                            <div class="f-l form form-horizontal" style="width:60%;">
                                
                                @php
                                    $key_data = DB::table('a_testdata_key')->select('id','data_key','data_unit')->where([
                                        ['std_id','=',$gaiyao_data->std_id],
                                        ['tool_id','=',$gaiyao_data->tool_id],
                                        ['item_id','=',$val->item_id]
                                    ])->orderBy('sort')->get();
        
                                    foreach ($key_data as $k => $v) {
                                        // $str = 'val' . $k;
                                        // echo '<span>' . $v->data_key . "<input type='text' name='$str' value='{$val->$str}' >" . $v->data_unit . '&emsp;' . '</span>';
                                        $input_data = DB::table('a_input_data')->where([
                                            ['sample_info_id','=',$sample_info_data->id],
                                            ['testdata_key_id','=',$v->id]
                                        ])->first();
                                        if ($input_data) {
                                            $html = <<<eof
                                                    <div class="row cl">
                                                        <label class="form-label col-xs-4"><b>{$v->data_key}：</b></label>
                                                        <div class="formControls col-xs-5">
                                                            <input type='text' class="input-text" name="val[{$input_data->id}]" value='{$input_data->val}'>
                                                        </div>
                                                        <label class="form-label t-a-l col-xs-3">{$v->data_unit}</label>
                                                    </div>
eof;
                                        }else{
                                            //如果记录不存在，则插入
                                            $input_data_id = DB::table('a_input_data')->insertGetId(
                                                ['sample_info_id' => $sample_info_data->id, 'testdata_key_id' => $v->id]
                                            );
                                            $html = <<<eof
                                                    <div class="row cl">
                                                        <label class="form-label col-xs-4"><b>{$v->data_key}：</b></label>
                                                        <div class="formControls col-xs-5">
                                                            <input type='text' class="input-text" name="val[$input_data_id]" value=''>
                                                        </div>
                                                        <label class="form-label t-a-l col-xs-3">{$v->data_unit}</label>
                                                    </div>
eof;
                                        }
                                        echo $html;
                                    }
                                @endphp
                            </div>
                            <div class="form form-horizontal" style="width:39%;">
                                <div class="row cl">
                                    <label class="form-label col-xs-4"><b>备注：</b></label>
                                </div>
                            </div>
                            <div class="form form-horizontal" style="width:99%;">
                                <div class="row cl">
                                    <div class="formControls col-xs-12">
                                        <textarea class="textarea" name="remark">{{$val->remark}}</textarea>
                                    </div>
                                </div>
                            </div>
                            
                            <div style="clear:both"></div>
                        </div>

                        <hr style='margin:5px;background-color:#ddd;height:1px;width:100%;border:none;'>
                        <b style="color:blue">试验日期</b>&emsp;
                        <input type="text" id="utime" name="utime" readonly value="{{$val->utime?date("Y-m-d",strtotime($val->utime)):date("Y-m-d",time())}}" onfocus="WdatePicker({})" class="input-text Wdate" style="width:180px">
                        
                        <div class="mt-10">
                            <span class="r">
                                &emsp;<input type="submit" value="保 存" class="btn btn-primary radius">
                            </span>
                            <span class="r mr-30">
                                <select name="res" style="height:30px;width:78px">
                                    <option value="1">符合</option>
                                    <option value="0">不符合</option>
                                </select>
                            </span>
                            @csrf
                        </div>
                        <div style="clear:both"></div>
                    </div>
                </li>
            </form>
        @endforeach
        </ul>

    </article>

    <script type="text/javascript" src="/admin/lib/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="/admin/lib/layer/3.1.1/layer.js"></script>
    <script type="text/javascript" src="/admin/static/h-ui/js/H-ui.min.js"></script>
    <script type="text/javascript" src="/admin/static/h-ui.admin/js/H-ui.admin.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/validate-methods.js"></script>
    <script type="text/javascript" src="/admin/lib/jquery.validation/1.14.0/messages_zh.js"></script>
    <script type="text/javascript" src="/admin/lib/My97DatePicker/4.8/WdatePicker.js"></script>
    <script>
$(function(){
    $("#Huifold").Huifold({
        titCell:'.item h4',
        mainCell:'.item .info',
        type:1,
        trigger:'click',
        className:"selected",
        // speed:"fast",//"slow" | "normal" | "fast"
        speed:0
    });

    //默认展开第一个
    $("#Huifold li").first().find('h4').trigger("click");

    // $("input:submit").click(function(){
    //     $("form").removeClass("form");
	// 	$(this).closest("form").addClass("form");
    // });
    
    @if ($commit >=1)
        $("input:text").attr("disabled",true);
        $("textarea").attr("disabled",true);
        $("select").attr("disabled",true);
        $("input:submit").addClass("disabled").removeClass("btn-primary");
    @endif

    var index2;

    @foreach ($items_data as $key=>$val)
    $('#form-@php echo $key; @endphp').validate({
        rules:{
            utime:{
                required:true,
            },
            wea:{
                required:true,
                notSpace:true,
            },
            temp:{
                required:true,
                number:true,
                range:[-40,60],
            },
            hum:{
                required:true,
                number:true,
                range:[1,100],
            },
            pressure:{
                required:true,
                number:true,
                range:[1,150],
            },
        },
        // onkeyup:false,
        // focusCleanup:false,
        success:"valid",
        submitHandler:function(form){
            $(form).ajaxSubmit({
                type: 'post', 
                url: "",//自己提交给自己可以不写url   
                //beforeSend  beforeSubmit
                
                beforeSend : function () { 
                    //0.4透明度 白色遮罩
                    index2 = layer.load(2,{ shade: [0.3,'#fff'] }); 
                },
                complete : function () { 
                    layer.close(index2); 
                },
                success: function(data) {
                    //判断修改结果 
                    if(data === '1'){ 
                        window.location.reload();//刷新
                        parent.table_reload(0);//0停留在当前页，1回到第一页
                        parent.layer.msg('保存成功!', { icon: 1, time:1000 });
                        // layer_close();//关闭自己
                    }else if(data === '2'){ 
                        window.location.reload();//刷新
                        parent.layer.msg('该样品已提交!',{ icon: 2, time:3000 });
                    }else{
                        layer.msg('操作失败!', { icon: 2, time: 2000 }); 
                    } 
                }, 
                error: function(data) {
                    ajax_error(data);
                }
            }); 
        }
    });
    @endforeach

/* 因天气获取接口有变动，暂时先注释掉 */
    /* 获取实时天气 */
   /*  $.ajax({
        type: 'GET',
        url: '/{{config('constant.name_admin')}}/myapi/getWeather',
        success: function(data){
            $("input[name='wea']").each(function () {
                if ($(this).val()==='') {
                    $(this).val(data.wea);
                }
            });
            $("input[name='pressure']").each(function () {
                if ($(this).val()==='') {
                    $(this).val(data.pressure);
                }
            });
           
        },
        error:function(data) {
            ajax_error(data);
        },
    });	 */

    /* 去缓存获取天气 */
    $("input[name='wea']").each(function () {
        if ($(this).val()==='') {
            $(this).val('{{ Cache::get('wea', '') }}');
        }
    });
    /* 去缓存获取气压 */
    $("input[name='pressure']").each(function () {
        if ($(this).val()==='') {
            $(this).val('{{ Cache::get('pressure', '') }}');
        }
    });

    /* 去缓存获取温度 */
    $("input[name='temp']").each(function () {
        if ($(this).val()==='') {
            $(this).val('{{ Cache::get('temp', '') }}');
        }
    });
    /* 去缓存获取湿度 */
    $("input[name='hum']").each(function () {
        if ($(this).val()==='') {
            $(this).val('{{ Cache::get('hum', '') }}');
        }
    });
});

/*查看上一个 下一个样品*/
function goto_pre_next(id){
    window.location.href="/{{config('constant.name_admin')}}/itemData/index?id=" + id;
}

    </script>
</body>

</html>